package edu.isquen.core.form.model.element;

import java.util.HashMap;
import java.util.Map;

import edu.isquen.core.document.model.Document;
import edu.isquen.core.document.model.Item;
import edu.isquen.core.form.model.Form;
import edu.isquen.util.CommUtil;

public class FormField implements FormElement {

	private static final long serialVersionUID = -971571151381255697L;

	protected String id;

	protected String name;

	protected String formid;
	
	protected Form _form;

	protected String discription;
	
	protected String fieldType;
	
	protected Map<String, String> _otherprops = new HashMap<String, String>();
	
	public String toHTML() {
		return "";
	}
	
	public Item createItem(Document doc, Object value) {
		Item item = doc.findItem(getName());

		if (item == null) {
			item = new Item();
			try {
				item.setId(CommUtil.getUUID().toString());
			} catch (Exception e) {
				e.printStackTrace();
			}
			item.setName(getName());
		}

		item.setType(this.getFieldType());

		if (value != null) {
			item.setValue(value);
		}

		doc.addItem(item);

		return item;
	}
	
	public void addOtherProps(String key, String value) {
		if (key != null && value != null)
			_otherprops.put(key, value);
	}

	public Map<String, String> get_otherprops() {
		return _otherprops;
	}

	public void set_otherprops(Map<String, String> otherprops) {
		_otherprops = otherprops;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFormid() {
		return formid;
	}

	public void setFormid(String formid) {
		this.formid = formid;
	}

	public String getDiscription() {
		return discription;
	}

	public void setDiscription(String discription) {
		this.discription = discription;
	}
	
	public Form get_form() {
		return _form;
	}

	public void set_form(Form form) {
		_form = form;
	}
	
	public String getFieldType() {
		return fieldType;
	}

	public void setFieldType(String fieldType) {
		this.fieldType = fieldType;
	}
}
